/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatsystem.observable;

import java.util.ArrayList;
import java.util.Observable;

/**
 *
 * @author Nargisse
 */
public class ListeConversation extends Observable{
    
    private ArrayList<Conversation> listConv;
    
    public ListeConversation(){
        this.listConv = new ArrayList<Conversation>();
    }
    
    
    public void addConversationToList(String userName, String message, boolean isLocalUserConv, boolean isErrorMessage){
        listConv.add(new Conversation(userName, message, isLocalUserConv, isErrorMessage));
        setChanged();
        notifyObservers(new Conversation(userName, message, isLocalUserConv, isErrorMessage));
        //notifyObservers(new Conversation(userName, message));
    }
    
    public void removeConversationFromList(String userName){
        int index = 0;
        
        while(index < listConv.size() && !listConv.get(index).getUserNameFromCov().equals(userName)){
            index++;
        }
        if(index == listConv.size()){
            System.out.println("Issue with Conversation...NOT found");
        }else{
            listConv.remove(index);
        }
    }
    
    public int getSize() {
        return this.listConv.size();
    }

    public Conversation getElementAt(int index) {
        return this.listConv.get(index);
    }
    
}
